package com.gulimall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gulimall.product.vo.SpuInfoVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gulimall.product.dao.SpuInfoDao;
import com.gulimall.product.entity.SpuInfoEntity;
import com.gulimall.product.service.SpuInfoService;

/**
 * @author ht
 */
@Service("spuInfoService")
public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
    @Override
    public IPage<SpuInfoVo> queryPage(Page<SpuInfoVo> spuInfoPage, SpuInfoEntity spuInfo, String key) {
        LambdaQueryWrapper<SpuInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(null != spuInfo.getBrandId() && spuInfo.getBrandId() != 0, SpuInfoEntity::getBrandId, spuInfo.getBrandId());
        queryWrapper.eq(null != spuInfo.getCatalogId(), SpuInfoEntity::getCatalogId, spuInfo.getCatalogId());
        queryWrapper.eq(null != spuInfo.getPublishStatus(), SpuInfoEntity::getPublishStatus, spuInfo.getPublishStatus());
        if (StringUtils.isNotEmpty(key)) {
            queryWrapper.like(SpuInfoEntity::getSpuName, key)
                    .or().like(SpuInfoEntity::getWeight, key)
                    .or().like(SpuInfoEntity::getSpuDescription, key);
        }
        return spuInfoPage.setRecords(baseMapper.list(spuInfoPage, spuInfo, queryWrapper));
    }
}